<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Cmspage
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Cmspage_Form_Admin_Manage_Filter extends Engine_Form {
	
	public function init() {
		$this->clearDecorators ()->addDecorator ( 'FormElements' )->addDecorator ( 'Form' )->addDecorator ( 'HtmlTag', array ('tag' => 'div', 'class' => 'search' ) )->addDecorator ( 'HtmlTag2', array ('tag' => 'div', 'class' => 'clear' ) );
		
		$this->setAttribs ( array ('id' => 'filter_form', 'class' => 'global_form_box' ) );
		
		$categories = Engine_Api::_ ()->cmspage ()->getCategories ();
		$categories_prepared = Engine_Api::_ ()->cmspage ()->convertCategoriesToArray ( $categories );
		$categories_prepared = array ("" => "" ) + $categories_prepared;
		
		$this->addElement ( 'Select', 'category', array ('label' => 'Category', 'filters' => array (new Radcodes_Lib_Filter_Null () ), 'multiOptions' => $categories_prepared ) );
		
		$this->addElement ( 'Text', 'search', array ('label' => 'Keyword', 'attribs' => array ('size' => 10 ) ) );
		
		$this->addElement ( 'Text', 'username', array ('label' => 'Username', 'attribs' => array ('size' => 10 ) ) );
		
		$this->addElement ( 'Select', 'published', array ('label' => 'Status', 'multiOptions' => array ('' => '', '1' => 'Published', '0' => 'Draft' ) ) );
		
		$yes_no = array ('' => '', '1' => 'Yes', '0' => 'No' );
		
		$this->addElement ( 'Select', 'featured', array ('label' => 'Featured', 'multiOptions' => $yes_no ) );
		
		$this->addElement ( 'Select', 'sticky', array ('label' => 'Sticky', 'multiOptions' => $yes_no ) );
		
		foreach ( $this->getElements () as $fel ) {
			if ($fel instanceof Zend_Form_Element) {
				
				$fel->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'Label', array ('tag' => null, 'placement' => 'PREPEND' ) )->addDecorator ( 'HtmlTag', array ('tag' => 'div', 'id' => $fel->getName () . '-search-wrapper', 'class' => 'form-search-wrapper' ) );
			
			}
		}
		
		$submit = new Engine_Form_Element_Button ( 'filtersubmit', array ('type' => 'submit' ) );
		$submit->setLabel ( 'Search' )->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'HtmlTag', array ('tag' => 'div', 'class' => 'buttons' ) )->addDecorator ( 'HtmlTag2', array ('tag' => 'div' ) );
		
		$this->addElement ( $submit );
		
		$this->addElement ( 'Hidden', 'order', array ('order' => 1001 ) );
		
		$this->addElement ( 'Hidden', 'order_direction', array ('order' => 1002 ) );
		
		$this->setAction ( Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array ('module' => 'cmspage', 'controller' => 'manage' ), 'admin_default', true ) );
	
	}
	
	public function initBAK() {
		$this->clearDecorators ()->addDecorator ( 'FormElements' )->addDecorator ( 'Form' )->addDecorator ( 'HtmlTag', array ('tag' => 'div', 'class' => 'search' ) )->addDecorator ( 'HtmlTag2', array ('tag' => 'div', 'class' => 'clear' ) );
		
		$this->setAttribs ( array ('id' => 'filter_form', 'class' => 'global_form_box' ) );
		
		$search = new Zend_Form_Element_Text ( 'search' );
		$search->setLabel ( 'Keyword' )->//   ->setAttrib('size', 10)
		clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'Label', array ('tag' => null, 'placement' => 'PREPEND' ) )->addDecorator ( 'HtmlTag', array ('tag' => 'div' ) );
		
		$username = new Zend_Form_Element_Text ( 'username' );
		$username->setLabel ( 'Username' )->setAttrib ( 'size', 10 )->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'Label', array ('tag' => null, 'placement' => 'PREPEND' ) )->addDecorator ( 'HtmlTag', array ('tag' => 'div' ) );
		
		$categories = Engine_Api::_ ()->cmspage ()->getCategories ();
		$categories_prepared = Engine_Api::_ ()->cmspage ()->convertCategoriesToArray ( $categories );
		$categories_prepared = array ("" => "" ) + $categories_prepared;
		
		$category = new Zend_Form_Element_Select ( 'category' );
		$category->setLabel ( 'Category' )->setFilters ( array (new Radcodes_Lib_Filter_Null () ) )->setMultiOptions ( $categories_prepared )->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'Label', array ('tag' => null, 'placement' => 'PREPEND' ) )->addDecorator ( 'HtmlTag', array ('tag' => 'div' ) );
		
		$published = new Zend_Form_Element_Select ( 'is_published' );
		$published->setLabel ( 'Status' )->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'Label', array ('tag' => null, 'placement' => 'PREPEND' ) )->addDecorator ( 'HtmlTag', array ('tag' => 'div' ) )->setMultiOptions ( array ('' => '', '1' => 'Published', '0' => 'Draft' ) );
		
		$featured = new Zend_Form_Element_Select ( 'is_featured' );
		$featured->setLabel ( 'Featured' )->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'Label', array ('tag' => null, 'placement' => 'PREPEND' ) )->addDecorator ( 'HtmlTag', array ('tag' => 'div' ) )->setMultiOptions ( array ('' => '', '1' => 'Yes', '0' => 'No' ) );
		
		$sticky = new Zend_Form_Element_Select ( 'is_sticky' );
		$sticky->setLabel ( 'Sticky' )->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'Label', array ('tag' => null, 'placement' => 'PREPEND' ) )->addDecorator ( 'HtmlTag', array ('tag' => 'div' ) )->setMultiOptions ( array ('' => '', '1' => 'Yes', '0' => 'No' ) );
		
		$submit = new Zend_Form_Element_Button ( 'filtersubmit', array ('type' => 'submit' ) );
		$submit->setLabel ( 'Search' )->clearDecorators ()->addDecorator ( 'ViewHelper' )->addDecorator ( 'HtmlTag', array ('tag' => 'div', 'class' => 'buttons' ) )->addDecorator ( 'HtmlTag2', array ('tag' => 'div' ) );
		
		$this->addElement ( 'Hidden', 'order', array ('order' => 1001 ) );
		
		$this->addElement ( 'Hidden', 'order_direction', array ('order' => 1002 ) );
		
		$this->addElements ( array ($search, $username, $category, 

		$featured, $sticky, $published, $submit ) );
		
		// Set default action
		$this->setAction ( Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array ('module' => 'cmspage', 'controller' => 'manage' ), 'admin_default', true ) );
	}
}